package com.example.work4.view

import android.annotation.SuppressLint
import android.app.AlertDialog
import android.app.Dialog
import android.content.Context
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.widget.Button
import android.widget.EditText
import android.widget.TextView
import com.example.work4.R
import com.example.work4.common.FIN

@SuppressLint("StaticFieldLeak")
class EditMessageDialog(var context: Context,var onClickListener: View.OnClickListener ) {
    var sendButton: Button?=null
    var input: EditText? = null
    val dialog: Dialog? = null
    var close : Button? = null

    fun show(){
        val myView: View =
            LayoutInflater.from(context).inflate(R.layout.dialog_comment, null)
        myView.setPadding(0, 0, 0, 0)
        val dialog: Dialog = AlertDialog.Builder(context)
            .setView(myView).create()
        dialog.window?.setGravity(Gravity.BOTTOM)
        sendButton = myView.findViewById(R.id.sendComment)
        input = myView.findViewById(R.id.commentInput)
        input?.requestFocus()
        sendButton?.setOnClickListener(onClickListener)
        close = myView.findViewById(R.id.close)
        close?.setOnClickListener(onClickListener)
        dialog.show()
        FIN.ListFragmentHandler?.sendEmptyMessageDelayed(FIN.OPENBOARDKEY,100);
    }

    fun close(text:TextView){
        text.text = input!!.text
        dialog?.dismiss()
    }
}